// 初始化按钮状态

export default function updateButtonStatus() {
    const {
        tabKey, orgVal, contractPage, contractPageInfo,
        agreementPage, agreementPageInfo, searched
    } = this.state;

    const orgFlag = !!orgVal.refpk;
    if (!orgFlag) {
        if (tabKey !== 'contract' || contractPage !== 'main' || agreementPage !== 'main') {
            this.setState({
                tabKey: 'contract',
                contractPage: 'main',
                agreementPage: 'main'
            })
        }
    }
    const isEdit = (tabKey === 'contract' && contractPage === 'edit') || (tabKey === 'agreement' && agreementPage === 'edit');
    const isView = (tabKey === 'contract' && contractPage === 'view') || (tabKey === 'agreement' && agreementPage === 'view');
    this.props.button.setButtonVisible({
        query: orgFlag && !isEdit && !isView,
        refresh: orgFlag && !isEdit && !isView,
        edit: isView,
        browse: isView,
        viewbooklet: orgFlag && tabKey === 'contract' && !isEdit && !isView,
        viewAgree: orgFlag && tabKey === 'agreement' && !isEdit && !isView,
        file: isView,
        export: orgFlag && !isEdit && !isView,
        print: orgFlag && !isEdit && !isView,
        tempPrint: orgFlag && !isEdit && !isView,
        save: orgFlag && isEdit && !isView,
        cancel: orgFlag && isEdit && !isView
    });

    const contFlag = tabKey === 'contract' && contractPageInfo.total === 0;
    const agreeFlag = tabKey === 'agreement' && agreementPageInfo.total === 0;
    this.props.button.setButtonDisabled({
        viewbooklet: contFlag,
        viewAgree: agreeFlag,
        export: agreeFlag || contFlag,
        print: agreeFlag || contFlag,
        tempPrint: agreeFlag || contFlag
    });
}
